#include<iostream>
#include<cmath>
#include<vector>
#include "../programming1/EquationSolver.h"
using namespace std;

class LinearSpline {
private:
	vector <double> x, f;	
public:
	LinearSpline(const vector<double>& x, const vector<double>& f) : x(x), f(f) {}
	double getValue(const double & _x) {
		int i = upper_bound(x.begin(), x.end(), _x) - x.begin() - 1;
		double h = _x - x[i], c0 = f[i], c1 = (f[i+1] - f[i]) / (x[i+1] - x[i]);
		return c0 + c1 * h;
	}
};

LinearSpline LinearSplineInterpolation( Function & f, const double& l, const double& r, const int& n) {
	vector <double> x(n+1), y(n+1);
	for(int i = 0; i <= n; ++ i){
        x[i] = l + (r - l) / n * i, y[i] = f(x[i]);
    }
     
	return LinearSpline (x, y);
}